/* 
保存Cookie 
c_name--key 
value---value 
默认时长为一年 
*/  
function setCookie(c_name, value, expiredays) {  
    var exdate = new Date();  
    exdate.setDate(exdate.getDate() + expiredays);  
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + exdate.toGMTString());  
}  
/* 
获取Cookie,根据c_name--key值来获取 
*/  
function getCookie(c_name) {  
    if (document.cookie.length > 0) {  
        var c_start = document.cookie.indexOf(c_name + "=");  
        if (c_start != -1) {  
            c_start = c_start + c_name.length + 1;  
            var c_end = document.cookie.indexOf(";", c_start);  
            if (c_end == -1) {  
                c_end = document.cookie.length;  
            }  
            return unescape(document.cookie.substring(c_start, c_end));  
        }  
    }  
    return "";  
}

/* 
递归换肤 
*/  
/*function changeSkin(winObj, cssPath) {  
    var frames = winObj.frames; 
    alert(frames);
    for (var i = 0; i < frames.length; i++) {  
        //证明是该页面是框架页面  
        //alert(frames[i].name + ":" + frames[i].frames.length);  
        if (frames[i].frames.length > 0) {  
            //判断页面中是否存在iframe             
            iframes = frames[i].document.getElementsByTagName("iframe");  
            if(iframes.length > 0){//如果页面含有iframe,那么此页面也需要换肤  
                var linkObj = frames[i].document.getElementById("style"); //获取link对象  
                alert('ddddddddddd'+linkObj);
                if (linkObj != null) {  
                    linkObj.href = "/ossp-web/static/theme/" + cssPath + "/main0.css";  
                }  
            }  
            //alert("iframes:" + iframes.length);  
            changeSkin(frames[i], cssPath);//递归换肤  
            window.reload();
        } else {  
            //非框架页面,换肤  
            var linkObj = frames[i].document.getElementById("style"); //获取link对象  
            alert('ddddddddddd'+linkObj);
            if (linkObj != null) {  
                linkObj.href = "/ossp-web/static/theme/" + cssPath + "/main0.css";  
            } 
            window.reload();
        }  
    }  
}*/
function changeSkin(winObj,cssPath){
	var link = document.getElementById("style"); 
	if(link!=null && link!=''){
		link.href = "/ossp-web/static/skin/" + cssPath + "/css/main0.css"; 
	}
}


var finalCssPath='';  //最终皮肤包   确认选择之后
var finalChoose='';    //最终选择
function chooseSkin(){
	if(confirm('确认选择该皮肤吗？')){
		setCookie('cssPath',finalCssPath,365);
		setCookie('choose',finalChoose,365);
		$("#closeWin").click();
	}
}

/* 
调用此方法来改变CSS样式
*/  
function changeCss(winObj, i ,len) {
	for(var num=0;num<len;num++ ){
		if(num==i){
			$("#select"+i).css({'border-width':'1px','border-color':'#f00','border-style':'solid'});
		}
		else{
			$("#select"+num).css({'border-width':'0px','border-color':'white','border-style':'none'});
		}
	}
	var cssPath = $("#imgId"+i).attr("value");
	finalCssPath = cssPath;
	finalChoose = "#select"+i;
	changeSkin(winObj, cssPath); //换肤   
} 